<script setup>
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
const { currentRoute } = useRouter();
import { ElMessage } from 'element-plus'
const router = useRouter();
import { token } from "@/utils/api.js"


// 正式
const gettoken = async () => {
  window.sessionStorage.setItem('token', currentRoute.value.query.token);
  let res = await token(currentRoute.value.query.token)
  if (res.code == '200') {
    let data = res.data;
    let msg = {
      username: data.username,
      zhName: data.zhName,
      manageList: data.manageList,
      areaId: data.areaId,
      siteId: data.siteId
    }
    window.sessionStorage.setItem('usermsg', JSON.stringify(msg));
    window.sessionStorage.setItem('username', data.username);
    router.push({ path: '/home' });
  } else {
    ElMessage({
      message: res.msg,
      type: 'warning',
    })
  }
}

// 测试
const login = async () => {
  window.sessionStorage.setItem('token', 'eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiJ7XCJ1c2VybmFtZVwiOlwiMTU3MTExNjA4NTZcIixcInpoTmFtZVwiOm51bGwsXCJhcmVhSWRcIjpcIjAwMDAxNTNcIixcInNpdGVJZFwiOlwiYmVpZGFnYW5nU2l0ZVwiLFwiaWNvblwiOm51bGwsXCJtYW5hZ2VMaXN0XCI6W1wiYmVpZGFnYW5nU2l0ZVwiXSxcInJvbGVMaXN0XCI6W10sXCJhdXRob3JpdGllc1wiOm51bGwsXCJhY2NvdW50Tm9uRXhwaXJlZFwiOm51bGwsXCJhY2NvdW50Tm9uTG9ja2VkXCI6bnVsbCxcImNyZWRlbnRpYWxzTm9uRXhwaXJlZFwiOm51bGwsXCJlbmFibGVkXCI6bnVsbCxcInVzZXJJZFwiOlwiYmVpZGFnYW5nVXNlcjAwMVwiLFwid3l5VG9rZW5cIjpudWxsfSIsImV4cCI6MTc0NTgxODczNH0.fvJ9yVA9W6Z4C_hRKH5HT3_HaT7FOfgYUVAuXonyagnikV28FK-lCYzILEliU4n5Df9EXbMpLAtM1jfyPwtyDYT1jpY2OhgWPGkBRkBc5HMpI3IkiJs_EYhjPzTSQyPrzuq4npbR0OmX8BODhvkoZKKYCtHjgGzA9Nu_GVkx9H1g-J1wOtJPCGa_GKIIsxjuYk1IyncFxfP9j8SHSCoHB8yXbuaVKyMCCgHt4B30T0Z9LqE2wbKTAELAQFwRTm_ZFj2tc1CvzX8I5A2FPzazi9i_AJaQcGPTrvdHBe8DDjT1MQdYvuN7Ebd6vfGKMNQaKTZJq5KppuIprCHUL0QwEA');
  let msg = {
    username: "15711160856",
    zhName: "王曦",
    manageList: ["wulingshanSite"],
    areaId: "0000153",
    siteId: "wulingshanSite"
  }
  window.sessionStorage.setItem('usermsg', JSON.stringify(msg));
  router.push({ path: '/home' });
}

onMounted(() => {
  // 正式
  if (currentRoute.value.query.token == undefined) {
    alert('您暂无权限查看，请登录后再查看')
  } else {
    gettoken();
  }
  //测试
  // login();
})

</script>
<template>
  <div></div>
</template>
<style scoped></style>